package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.bo.LogiSysSettingEditBo;
import com.piggy.logi.sys.bo.LogiSysSettingQueryBo;
import com.piggy.logi.sys.service.ILogiSysSettingService;
import com.piggy.logi.sys.vo.LogiSysSettingVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 物流系统设置Controller
 *
 * @author piggy
 * @date 2023-11-13
 */
@Api(value = "物流系统设置控制器", tags = {"物流系统设置管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/setting")
public class LogiSysSettingController extends BaseController {

    private final ILogiSysSettingService iLogiSysSettingService;

    /**
     * 查询物流系统设置列表
     */
    @ApiOperation("查询物流系统设置列表")
    //@SaCheckPermission("sys:setting:list")
    @GetMapping("/list")
    public TableDataInfo<LogiSysSettingVo> list(@Validated LogiSysSettingQueryBo bo) {
        return iLogiSysSettingService.queryPageList(bo);
    }

    /**
     * 获取物流系统设置详细信息
     */
    @ApiOperation("获取物流系统设置详细信息")
    //@SaCheckPermission("sys:setting:query")
    @GetMapping("/{id}")
    public R<LogiSysSettingVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iLogiSysSettingService.queryById(id));
    }

    /**
     * 新增物流系统设置
     */
    @ApiOperation("新增物流系统设置")
    //@SaCheckPermission("sys:setting:add")
    @Log(title = "物流系统设置", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiSysSettingVo> add(@Validated @RequestBody LogiSysSettingEditBo bo) {
        return R.ok(iLogiSysSettingService.insertByAddBo(bo));
    }

    /**
     * 修改物流系统设置
     */
    @ApiOperation("修改物流系统设置")
    //@SaCheckPermission("sys:setting:edit")
    @Log(title = "物流系统设置", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiSysSettingVo> edit(@Validated @RequestBody LogiSysSettingEditBo bo) {
        return R.ok(iLogiSysSettingService.updateByEditBo(bo));
    }

    /**
     * 删除物流系统设置
     */
    @ApiOperation("删除物流系统设置")
    //@SaCheckPermission("sys:setting:remove")
    @Log(title = "物流系统设置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return R.ok(iLogiSysSettingService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
